package club.emergency.wechat.mistake_collection.search.provider.impl;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.mistake_collection.search.MistakeCollectionSearch;
import club.emergency.wechat.model.mistake_collection.MistakeCollection;
import club.emergency.wechat.persistence.mistake_collection.MistakeCollectionMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.mistake_collection.search.provider.impl
 * Date: 2018/12/23
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@RestController
public class MistakeCollectionSearchImpl implements MistakeCollectionSearch {

    private MistakeCollectionMapper mistakeCollectionMapper;

    public MistakeCollectionSearchImpl(MistakeCollectionMapper mistakeCollectionMapper) {
        this.mistakeCollectionMapper = mistakeCollectionMapper;
    }

    @Override
    public String flipList(@RequestParam("staffId") Long staffId, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        Page<MistakeCollection> page = new Page<>(pageNo, pageSize);
        QueryWrapper<MistakeCollection> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("staff_id", staffId);
        queryWrapper.orderByDesc("id");
        IPage<MistakeCollection> mistakeCollectionIPage = mistakeCollectionMapper.selectPage(page, queryWrapper);
        return ResponseEntity.ok(StatusCode.DB_SEARCH_OK, "根据人员查询错题记录成功！", mistakeCollectionIPage);
    }
}
